<template>
    <el-input v-model="query.sw" placeholder="名称" prefix-icon="el-icon-search" clearable @input="handleSearch"></el-input>
    <el-table :data="tableData" style="width: 100%;" @selection-change="handleSelection">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="code" label="编码" />
      <el-table-column prop="name" label="名称"  />
      <el-table-column prop="category" label="类别"/>
    </el-table>
  <div>
    <pagination v-model:size="query.pageSize" v-model:page="query.pageNum" :total="total" @pagination="getList" />
  </div>
    <div style="text-align: center">
    <el-button @click="handleClose" type="primary">确定</el-button>
  </div>
</template>
<script>
import Pagination from "../../component/pagination.vue";
import {listBySw as list} from '/http/signal.js'
export default {
  components: {Pagination},
  props:{
    initParams:Object
  },
  setup(props,context) {

    const tableData = ref([]);
    const total = ref(1);
    const dialog = ref(null);
    const selectRows = ref([])
    const options = ref([])
    const model = {
      sw: '',
      pageSize: 100,
      pageNum: 1
    }
    const query = reactive(Object.assign({}, model))
    const resetForm = () => {
      Object.assign(query, model);
    }
    const getList = () => {
      list(query).then(res => {
        tableData.value = res.data.data;
        total.value = parseInt(res.data.total);
      })
    }
    const handleSelection = (val) => {
      selectRows.value = val
    }
    const handleClose=()=>{
      context.emit('close',selectRows.value)
    }

    const handleSearch=(val)=>{
      getList()
    }

    onMounted(()=>{
        console.log(props.initParams)
    })


    getList();
    return {
      dialog,
      tableData,
      query,
      getList,
      resetForm,
      handleSelection,
      handleClose,
      total,
      handleSearch
    };
  }
}
</script>
<style scoped>

</style>